package com.yb.auth.core.handler;

import com.yb.core.bean.Resp;
import com.yb.core.constant.HttpConstant;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Copyright (C), 2022-2022, 姚兵
 * Author: 32210
 * Date: 2022/11/13 17:44
 * FileName: GlobalExceptionHandler
 * Description:
 */

@RestControllerAdvice
public class GlobalAuthExceptionHandler {


    @ExceptionHandler(BadCredentialsException.class)
    public Resp handle(BadCredentialsException e){
        return Resp.ok(HttpConstant.Response.INVALID_USER);
    }

    @ExceptionHandler(AccessDeniedException.class)
    public Resp handle(AccessDeniedException e){
        return Resp.ok(HttpConstant.Response.NO_PERMISSION);
    }
}
